package com.zyl.basis.syn;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author zhaoyl
 * @date 2024/5/27 17:26
 * @description 说明
 * CopyOnWriteArrayList 线程安全集合
 */

//JUC安全类型集合
public class TestJUC {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 5000; i++) {
            new Thread(()->{
                list.add(Thread.currentThread().getName());
            }).start();
        }

        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println(list.size());
    }
}

